﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


using Jungle.Code.Utils;
using Jungle.Prodamo.AdvertManager;

namespace Jungle.Prodamo.User.WebControls
{
    public class LastAdverts : WebControl
    {
        protected override void RenderContents(HtmlTextWriter writer)
        {
            Advert advs = new Advert();
            advs.GetAll();

            writer.AddAttribute("class", "advm_table");
            writer.RenderBeginTag(HtmlTextWriterTag.Table);
            writer.RenderBeginTag(HtmlTextWriterTag.Tr);
            writer.AddAttribute("class", "advm_td");
            writer.RenderBeginTag(HtmlTextWriterTag.Td);
            writer.Write("Последние объявления");
            writer.RenderEndTag();
            writer.RenderEndTag();

            int count = 0;
            foreach (Advert adv in advs.AdvertList)
            {
                if (count > 5) break;
                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                writer.RenderBeginTag(HtmlTextWriterTag.Td);

                writer.AddAttribute(HtmlTextWriterAttribute.Href, UrlHelper.GetSiteUrl() + "/ru/adverts.aspx?cmd=Show&Id=" + adv.AdvertId.ToString());
                writer.RenderBeginTag(HtmlTextWriterTag.A);
                    writer.Write(adv.Title);
                writer.RenderEndTag();

                writer.RenderEndTag();
                writer.RenderEndTag();
                count++;

            }

            writer.RenderEndTag(); 
            base.RenderContents(writer);
        }
    }
}
